<link rel="stylesheet" href="scripts/zebra_pagination/zebra_pagination.css" type="text/css" />
<link rel="stylesheet" href="scripts/tinytips/tinyTips.css" type="text/css" />
<script type="text/javascript" src="scripts/tinytips/jquery.tinyTips.js"></script>
<div class="navigation_title">
    <?php            
        include 'position.php';
    ?>
</div>
<div class="navigation_body" style="clear: both; position: relative; padding-top: 10px; overflow: auto;">
        <?php
        require 'admin/config.php';
        if(isset($_GET['kid']) && $_GET['kid'] != '')
            $kid = $_GET['kid'];
        else
            $kid = 0;
            
        if(isset($_GET['kid1']) && $_GET['kid1'] != '')
            $kid1 = $_GET['kid1'];
        else
            $kid1 = 0;
            
        if(isset($_GET['kid2']) && $_GET['kid2'] != '')
            $kid2 = $_GET['kid2'];
        else
            $kid2 = 0;
            
        if(isset($_GET['kid3']) && $_GET['kid3'] != '')
            $kid3 = $_GET['kid3'];
        else
            $kid3 = 0;
        // how many records should be displayed on a page?
        $records_per_page = 15;

        // include the pagination class
        require 'scripts/zebra_pagination/Zebra_Pagination.php';

        // instantiate the pagination object
        $pagination = new Zebra_Pagination();

        // set position of the next/previous page links
        $pagination->navigation_position('outside');

        // the MySQL statement to fetch the rows
        // note how we build the LIMIT
        // also, note the "SQL_CALC_FOUND_ROWS"
        // this is to get the number of rows that would've been returned if there was no LIMIT
        // see http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows
        $cmd = "";           
        
        if($kid3 != 0)
            $cmd .= " AND MaLoaiSanPhamCap3 = $kid3";
        elseif($kid2 != 0)
                $cmd .= " AND MaLoaiSanPhamCap2 = $kid2";
            elseif($kid1 != 0)
                    $cmd .= " AND MaLoaiSanPhamCap1 = $kid1";
                elseif($kid != 0)
                    $cmd .= " AND MaLoaiSanPham = $kid";
        
        $MySQL = "
            SELECT
                SQL_CALC_FOUND_ROWS
                *
            FROM
                giaphucvn_sanpham 
            WHERE (1)";
            
        $MySQL .= $cmd;
            
        $MySQL .= " 
            ORDER BY
                TenSanPham
            LIMIT
                " . (($pagination->get_page() - 1) * $records_per_page) . ', ' . $records_per_page . '
        ';


        // if query could not be executed
        if (!($result = @mysql_query($MySQL)))

            // stop execution and display error message
            die(mysql_error());

        // fetch the total number of records in the table
        $rows = mysql_fetch_assoc(mysql_query('SELECT FOUND_ROWS() AS rows'));

        // pass the total number of records to the pagination class
        $pagination->records($rows['rows']);

        // records per page
        $pagination->records_per_page($records_per_page);

        ?>
        <?php
            $k = 2;
            while ($row = mysql_fetch_assoc($result))
            {
                if($k%3 == 0)
                {
                    $cen = ' cen';
                    $k = 0;
                }
                else
                    $cen = '';
                
                $HinhNho = explode('|', $row["HinhNho"]);
                
                echo "<div class='product $cen'>
                        <a href='index.php?root=pro&kid={$row["MaLoaiSanPham"]}&kid1={$row["MaLoaiSanPhamCap1"]}&kid2={$row["MaLoaiSanPhamCap2"]}&kid3={$row["MaLoaiSanPhamCap3"]}&cont=chitiet_sanpham&sid={$row["MaSanPham"]}'>
                        <span><img style='width: 150px; height: 150px;' src='images/sanpham/hinhnho/{$HinhNho[0]}' /></span>
                        <span>{$row["TenSanPham"]}</span>
                        </a>
                        <span class='rice'>{$row["GiaGoc"]}</span>
                        <span>
                            <a href='index.php?cont=mua_sanpham&sid={$row["MaSanPham"]}'><img src='images/muahang.png' /></a>
                        </span>
                      </div>";
                $k++;
            }
        // render the pagination links
            $pagination->render();
        ?>
</div>
<div class="navigation_footer" style="clear: both;">
    &nbsp;
</div>
<script type="text/javascript">
    $(document).ready(function() {
    	//$('a.tTip').tinyTips('light', 'title');
    	$('a.imgTip').tinyTips('yellow', '<img src="scripts/tinytips/images/demo-image.jpg" /><br />You can even put images or any other markup in the tooltips.');
    	//$('img.tTip').tinyTips('green', 'title');
    	//$('h1.tagline').tinyTips('blue', 'tinyTips are totally awesome!');
    });
</script>